package com.company.indicationshots.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.widget.ImageView;

import com.company.indicationshots.R;
import com.company.indicationshots.model.Score;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
//主页面，当前射靶靶面描点绘制
public class PreShotTargetResultView {
    public void getTargetView(Context context, List<Map<String, Object>> scoreList, Map<String, Object> selectScoreMap, ImageView imageView) {

        // 加载背景图片
        Bitmap backgroundBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.chest_ring);
        // 创建一个新的Bitmap对象，尺寸与背景图片相同（或根据需要调整）
        Bitmap combinedBitmap = Bitmap.createBitmap(backgroundBitmap.getWidth(), backgroundBitmap.getHeight(), Bitmap.Config.ARGB_8888);

        // 初始化Canvas
        Canvas canvas = new Canvas(combinedBitmap);

        // 绘制背景图片
        canvas.drawBitmap(backgroundBitmap, 0, 0, null);

        Bitmap sticker;
        Bitmap scaledStickerBitmap;

        int newWidth = 90; // 新的宽度
        int newHeight = 90; // 新的高度

        for (int i = 0;i < scoreList.size();i++) {
            Map<String, Object> map = scoreList.get(i);
            // 加载贴图图片并绘制到Canvas上
            if ((Objects.equals(map.get("x"), selectScoreMap.get("x"))) && (Objects.equals(map.get("y"), selectScoreMap.get("y")))) {
                sticker = BitmapFactory.decodeResource(context.getResources(), R.drawable.bullet_hole_selected);
            } else {
                sticker = BitmapFactory.decodeResource(context.getResources(), R.drawable.bullet_hole);
            }
            // 创建一个缩放后的Bitmap对象
            scaledStickerBitmap = Bitmap.createScaledBitmap(sticker, newWidth, newHeight, false);
            // 绘制贴图图片到Canvas上
            canvas.drawBitmap(scaledStickerBitmap, (float) map.get("x"),(float) map.get("y"), null);
        }

        // 将合并后的图片设置到ImageView上
        imageView.setImageBitmap(combinedBitmap);
    }
}
